import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.*;

public class Test1 {

	public static void main(String[] args) {
		new MyFrame();
	}

}

class MyFrame extends JFrame{
	int m = 5;
	int n = 5;
	JLabel jb[][];
	int grideSize = 40;
	MyFrame(){
		//1.实例化一个JFrame的窗口
		JFrame jf = new JFrame("六子棋");
		
		//2.为窗口设置大小
		jf.setSize(1000,800);
		
		//3.
		jb = new JLabel[m + 1][n + 1];
		for(int i = 0;i < m;i++) {
			for(int j = 0;j < n;j++) {
				jb[i][j] = new JLabel();
				jb[i][j].setSize(grideSize, grideSize);
				jb[i][j].setLocation(i * grideSize + 20, j * grideSize + 20);
				jb[i][j].setBackground(Color.white);
				jb[i][j].setOpaque(true);
				jb[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
				jf.add(jb[i][j]);
			}
		}
		
		//4.
		JPanel jp = new JPanel();
		//
		JButton jb1 = new JButton("电脑先手");
		jp.add(jb1);
		jb1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				jb[0][0].setText("1");
				jb[0][1].setText("2");
				jb[0][2].setText("3");
				jb[1][0].setText("4");
				jb[1][1].setText("5");
				jb[2][0].setText("6");
			}
			
		});
		jf.add(jp);
		
		
		jf.setVisible(true);
		jf.setLocationRelativeTo(null);
		jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
				
	}
	
}